#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import sys

shipinId = sys.argv[1]

def searchKey(info,key):
	if key not in info:
		showAlert(key + "  key没加入info")
	return

def showAlert(info):
	print('\033[1;31;40m') 	#红色字体前缀
	print(info)
	print('\033[0m') 	#红色字体后缀
	return

#搜delegate.m
def searchDele(line, delegate):
	
	strlist = line.split(': ')

	print("开始检查 ------" + strlist[0]);
	if strlist[0]=="包名":
		return

	string='"'+strlist[0]+'"'
	if string not in delegate:
		showAlert(string + "  不存在delegate1")
		
	string='"'+strlist[1]+'"'
	if string not in delegate:
		showAlert(string + "  不存在delegate2")
	return

#搜info.plist
def searchInfo(line, info):
	# print("开始检查 info.plist------");
	strlist = line.split(': ')
	if strlist[0]=="包名" or strlist[0]=="wxKey" or strlist[0]=="qqKey":
		if strlist[0]=="qqKey":
			strlist[1]="tencent"+strlist[1]
		strlist[1]=">" + strlist[1] + "<"
		if strlist[1] not in info:
			showAlert(strlist[1] + "  不存在info")
	return
	


def main():
	#文件读取
	deleFile = open("AppDelegate.m","r",encoding="utf-8")
	delegate=deleFile.read()

	infoFile = open("Info.plist","r",encoding="utf-8")
	info=infoFile.read()
	
	cishu=0
	with open(shipinId, "r") as f:
	    for line in f.readlines():
	        line = line.strip('\n')  #去掉列表中每一个元素的换行符
	        if ":" in line:
	        	cishu=cishu+1
	        	searchDele(line, delegate)
	        	searchInfo(line, info)
	
	if cishu<10:
		showAlert("少了参数")
	searchKey(info, "NSCameraUsageDescription")
	searchKey(info, "NSLocationUsageDescription")
	searchKey(info, "NSMicrophoneUsageDescription")
	searchKey(info, "NSPhotoLibraryUsageDescription")
	searchKey(info, "NSUserTrackingUsageDescription")
	
	searchKey(info, "238da6jt44.skadnetwork")
	searchKey(info, "22mmun2rn5.skadnetwork")
	searchKey(info, "tbopen27860305")

	infoFile.close()
	deleFile.close()

main()
